package com.ypj.indusynergyems.web;

import com.ypj.indusynergyems.dao.entity.GoodsEntity;
import com.ypj.indusynergyems.service.MallSearchService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequiredArgsConstructor
public class SearchController {

    private final MallSearchService mallSearchService;


    /**
     * 自动将页面提交过来的所有请求查询参数转成我们指定的对象
     * @param
     * @return
     */
    @GetMapping("/list.html")
    public String listPage(@RequestParam(value = "catalog3Id",required = false) Integer catalog3Id, @RequestParam(value = "keyword",required = false) String keyword, Model model){
        List<GoodsEntity> result = mallSearchService.search(catalog3Id,keyword);
        model.addAttribute("result",result);
        return "/search/list";
    }

}
